﻿using System;
using System.Collections.Generic;
using System.Text;
using Watchdog.Dal;
using Watchdog.Bll;
using Watchdog.Bll.Base;

namespace Watchdog.Bll.Factory {

    public partial class DefinitionFactory {
        public static void AddTargetType ( Definition definition, TargetType targettype ) {
			Dal.DataClient.Current.DefinitionAddTargetType (definition.IntData, targettype.IntData );
		}
        public static void Delete ( DefinitionBase definition ) {
            DataClient.Current.DefinitionDelete ( definition.IntData );
        }

        public static Definition GetById ( int id ) {
            return new Definition (DataClient.Current.DefinitionGetById(id));
        }
				
        public static List<Definition> GetByTargetType ( int targettype ) {
		    List<Definition> outlist = new List<Definition> ();
            Watchdog.Facade.Definition[] list = Dal.DataClient.Current.DefinitionGetByTargetType ( targettype );
            foreach (Watchdog.Facade.Definition item in list)
                outlist.Add (new Definition (item));
            return outlist;
            // return DataClient.Current.DefinitionGetByTargetType ( targettype );
        }
        public static void Insert ( DefinitionBase definition ) {
            definition.IntData.Created = DateTime.Now;
            definition.IntData.Modified = DateTime.Now;
            definition.IntData = DataClient.Current.DefinitionInsert ( definition.IntData );
        }

        public static void RemoveTargetType ( Definition definition, TargetType targettype ) {
			Dal.DataClient.Current.DefinitionRemoveTargetType (definition.IntData, targettype.IntData );
		}
        public static void Update ( DefinitionBase definition ) {
            definition.IntData.Modified = DateTime.Now;
            DataClient.Current.DefinitionUpdate ( definition.IntData );
        }
		
	}
}
